CC = gcc -g
LEX = flex
YACC = bison
CFLAGS = -DYYDEBUG=1

# compatible unix, i can put windows file to unix, and make it ok.
DOS2UNIX = 1

DP = dp-server
DP_OBJ = dp_main.o dp_init.o dp_config.o main.o log.o dp_network.o
DP_INC = -I. -I./include

DP_PARSE = 

.PHONY:clean
	
all:	${DOS2UNIX} ${DP_PARSE} ${DP}

${DOS2UNIX}:
	@dos2unix *.[ch]

# dp-server
${DP}:${DP_OBJ}
	${CC} -o $@ ${DP_OBJ} ${DP_INC}


dp_main.o:dp_main.c log.h
	${CC} -c -o $@ $< ${DP_INC}

dp_config.o:dp_config.c log.h
	${CC} -c -o $@ $< ${DP_INC}

dp_init.o:dp_init.c
	${CC} -c -o $@ $< ${DP_INC}

main.o:main.c
	${CC} -c -o $@ $<
	
dp_network.o:dp_network.c dp_network.h
	${CC} -c -o $@ $<


# sql parser
${DP_PARSE}:	${DP_PARSE}.tab.o ${DP_PARSE}.o
	${CC} -o $@ ${DP_PARSE}.tab.o ${DP_PARSE}.o

${DP_PARSE}.tab.c ${DP_PARSE}.tab.h:	${DP_PARSE}.y
	${YACC} -v ${DP_PARSE}.y

${DP_PARSE}.c:	${DP_PARSE}.l
	${LEX} -o$@ $<

${DP_PARSE}.o:	${DP_PARSE}.c ${DP_PARSE}.tab.h
	${CC} -c ${DP_PARSE}.c ${DP_PARSE}.tab.h

clean:
	rm -f ${DP_PARSE} ${DP_PARSE}.tab.o ${DP_PARSE}.o \
	${DP_PARSE}.tab.c ${DP_PARSE}.tab.h 	${DP_PARSE}.c \
	${DP_PARSE}.output 
	rm -f *.o ${DP}

.SUFFIXES:	.l .y .c